package com.xxx.yuedong.mall.controller;

import com.github.pagehelper.PageInfo;
import com.xxx.yuedong.common.R;
import com.xxx.yuedong.mall.controller.form.ProductListForm;
import com.xxx.yuedong.mall.model.pojo.Product;
import com.xxx.yuedong.mall.model.query.ProductListQuery;
import com.xxx.yuedong.mall.service.ProductService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * 描述：     前台商品Controller
 * @author hc
 */
@RestController
@Api(tags = "前台商品相关接口")
@Slf4j
public class ProductController {

    @Autowired
    ProductService productService;

    @ApiOperation(value = "商品详情")
    @GetMapping("product/detail")
    public R detail(@RequestParam Integer id) {
        Product product = productService.detail(id);
        return R.ok().put("product",product);
    }

    @ApiOperation(value = "商品列表")
    @GetMapping("product/list")
    public R list(ProductListForm form) {
        log.debug("form + {}",form);
        PageInfo list = productService.list(form);
        return R.ok().put("list",list);
    }
}
